/*
 * @lc app=leetcode.cn id=1844 lang=typescript
 *
 * [1844] 将所有数字用字符替换
 */

// @lc code=start
function replaceDigits(s: string): string {
    const shift = (c: string, x: number) => {
        return String.fromCharCode(c.charCodeAt(0) + x);
    };
    let result = "";
    for (let i = 0; i < s.length; i++) {
        if (i % 2 === 0) {
            result += s[i];
            continue;
        }
        const prev = s[i - 1];
        const element = parseInt(s[i]);
        result += shift(prev, element);
    }
    return result;
}
// @lc code=end
